#include "Texture.h"

wchar_t* AnsiToUnicode(const char* szStr)
{
	int nLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0);
	if (nLen == 0)
	{
		return NULL;
	}
	wchar_t* pResult = new wchar_t[nLen];
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen);
	return pResult;
}

GTexture::GTexture(const char* pName)
{
	wchar_t* pszName = AnsiToUnicode(pName);
	if (m_pBmp != NULL)
	{
		delete m_pBmp;
	}
	m_pBmp = new Gdiplus::Bitmap(pszName);
}

int GTexture::GetPixel(int nX, int nY)
{
	m_pBmp->GetPixel(nX, m_pBmp->GetHeight() - 1 - nY, &m_col);
	return (m_col.GetRed() << 16) + (m_col.GetGreen() << 8) + m_col.GetBlue();
}

int GTexture::GetWidth()
{
	return m_pBmp->GetWidth();
}

int GTexture::GetHeight()
{
	return m_pBmp->GetHeight();
}